<?php
    include_once '../connection/databaseHandler.php';
    include_once '../connection/sessionHandler.php';
    $database = new DatabaseHandler();
    $session = new SessionHandler();

    $username_uploader = $_GET['id'];
    $photo_id = $_GET['photo-id'];
    $rate = $_GET['r'];
    $username_commentator = $session->username;

    $query_cek_user = "SELECT * FROM ".$database->t_fotomark."
                        WHERE
                            id_foto='$photo_id' AND
                            username_commentator='$username_commentator'";
    $result = $database->execQuery($query_cek_user);
    $count = mysql_num_rows($result);
    if ($count==0) {
        $query_insert =
        "INSERT INTO ".$database->t_fotomark."(
            id_foto,
            username_commentator,
            rate
        ) VALUES (
            '".$photo_id."',
            '".$username_commentator."',
            '".$_GET['r']."'
        )";
        if (!$database->execQuery($query_insert)) {
            
            header("location:../profile.php?page=photo-detail&id=".$username_uploader."&photo-id=".$photo_id."");
        }
        else {
            header("location:../profile.php?page=photo-detail&id=".$username_uploader."&photo-id=".$photo_id."");
        }

    }
    else
    {
        header("location:../profile.php?page=photo-detail&id=".$username_uploader."&photo-id=".$photo_id."");
    }

    ?>